// ocean_data_convertor.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "stdio.h"
#include "stdlib.h"
#include "math.h"

int _tmain(int argc, _TCHAR* argv[])
{
	FILE * fiIn = NULL;
	FILE * fiOut = NULL;

	fiIn = fopen("C:\\ricki_data.txt", "r");
	fiOut = fopen("C:\\ricki_data.dat", "wb");

	for(int i = 0; i < 32; ++i)
	{
		for(int j = 0; j < 32; ++j)
		{
			for(int k = 0; k < 33; ++k)
			{
				float fTmp = 1.0f;
				char szCurrLine[1024];
				fgets(szCurrLine, 1024, fiIn);
				int idx = 0;
				for(int iWhichData = 0; iWhichData < 3; ++iWhichData)
				{
					while(szCurrLine[idx] == ' ')
						++idx;

					sscanf(szCurrLine+idx, "%f", &fTmp);

					while(szCurrLine[idx] != ' ')
						++idx;
				}
				for(int iWhichData = 0; iWhichData < 10; ++iWhichData)
				{
					while(szCurrLine[idx] == ' ')
						++idx;

					sscanf(szCurrLine+idx, "%f", &fTmp);

					while(szCurrLine[idx] != ' ' && szCurrLine[idx] != '\0')
						++idx;

					unsigned char * pCharOut = (unsigned char *)((void *)&fTmp);
					for(int iByte = 0; iByte < 4; ++iByte)
					{
						fprintf(fiOut, "%c", pCharOut[iByte]);
					}
				}
				char c;
				fscanf(fiIn, "%c", &c);
				fscanf(fiIn, "%c", &c);
			}
		}
	}

	fclose(fiOut);
	fclose(fiIn);
	return 0;
}

